/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

import Clases.Consulta;
import Clases.Orden;
import Clases.OrdenDetalle;
import java.util.List;
import javax.swing.table.DefaultTableModel;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
import net.sf.jasperreports.engine.util.JRLoader;
import net.sf.jasperreports.view.JasperViewer;

/**
 *
 * @author Ricardo
 */
public class VerOrdenes extends javax.swing.JFrame {

    /**
     * Creates new form VerOrdenes
     */
    public VerOrdenes() {
        initComponents();
        if (Consulta.getOrden().size() > 0) {
            DefaultTableModel modelo = (DefaultTableModel) tablaOrdenes.getModel();
            String[] orden = new String[4];
            for (Orden o : Consulta.getOrden()) {
                orden[0] = o.getCodigoOrden();
                orden[1] = Consulta.getProveedor(o.getCodigoProveedor()).getNombre();
                orden[2] = "" + o.getDetalles().size();
                orden[3] = "" + o.getFecha();
                modelo.addRow(orden);
            }
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        popupvermas = new javax.swing.JPopupMenu();
        verMas = new javax.swing.JMenuItem();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tablaOrdenes = new javax.swing.JTable();

        verMas.setText("Ver Más");
        verMas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                verMasActionPerformed(evt);
            }
        });
        popupvermas.add(verMas);

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Ordenes");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Orden"));

        tablaOrdenes.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Código de Orden", "Proveedor", "Cantidad de Productos", "Fecha de Elaboración"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tablaOrdenes.setComponentPopupMenu(popupvermas);
        tablaOrdenes.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        tablaOrdenes.getTableHeader().setReorderingAllowed(false);
        jScrollPane1.setViewportView(tablaOrdenes);
        tablaOrdenes.getColumnModel().getColumn(0).setResizable(false);
        tablaOrdenes.getColumnModel().getColumn(1).setResizable(false);
        tablaOrdenes.getColumnModel().getColumn(2).setResizable(false);
        tablaOrdenes.getColumnModel().getColumn(3).setResizable(false);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 696, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 336, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 10, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void verMasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_verMasActionPerformed
        // TODO add your handling code here:
        int fila = tablaOrdenes.getSelectedRow();
        if (fila > -1) {
            String codigo = tablaOrdenes.getValueAt(fila, 0).toString();
            
            try {
                VerOrden vo = new VerOrden();
                vo.llenarTabla(codigo);
                vo.setVisible(true);
            } catch (Exception e) {
                System.out.print(e.getCause());
                e.printStackTrace();
               
                javax.swing.JOptionPane.showMessageDialog(null, "Ha Ocurrido un error Inesperado", "Error", 1);
            }
        }else{
            javax.swing.JOptionPane.showMessageDialog(null, "No ha seleccionado ninguna fila", "Seleccione una fila", 1);
        }

    }//GEN-LAST:event_verMasActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPopupMenu popupvermas;
    private javax.swing.JTable tablaOrdenes;
    private javax.swing.JMenuItem verMas;
    // End of variables declaration//GEN-END:variables
}
